package presentation.controller;

import logic.facade.SubjectFacade;
import logic.facade.TeacherFacade;
import java.util.List;
import vo.*;

/**
 *
 * @author Alexander
 */
public class SubjectPanelControl {

    public List<IValueObject> obtenerProfesores() {
        return new TeacherFacade().getList();
    }

    public TeacherVO buscarProfesor(int id) {
        return ((TeacherVO) new TeacherFacade().find(id));
    }

    public TeacherVO buscarProfesorPorNombre(String nombre, String apellido) {
        return new TeacherFacade().finByName(nombre, apellido);
    }

    public void crearMateria(SubjectVO vo) {
        for (GroupVO grupo : vo.getGroups()) {
            grupo.setId(vo.getCode() + "-" + grupo.getGroupNumber());
            grupo.setSubjectId(vo.getCode());
            for (ClassDayVO dia : grupo.getClassDays()) {
                dia.setGroupId(grupo.getId());                
            }
        }

        new SubjectFacade().create(vo);
    }
    
    public boolean updateSubject (SubjectVO vo){
        for (GroupVO grupo : vo.getGroups()) {
            grupo.setId(vo.getCode() + "-" + grupo.getGroupNumber());
            grupo.setSubjectId(vo.getCode());
            for (ClassDayVO dia : grupo.getClassDays()) {
                dia.setGroupId(grupo.getId());
            }
        }
        return new SubjectFacade().update(vo);
    }
    
    public boolean deleteSubject (int codeSubject){
        return new SubjectFacade().delete(codeSubject);
    }
    
    public List<SubjectVO> getSubjects(){
        return new SubjectFacade().getSubjects();
    }
    
}
